package galatea;

import java.awt.Color;
import java.awt.Component;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

public class ListRenderer extends JLabel implements ListCellRenderer{
	Color color;
    public ListRenderer() {
        setOpaque(true);
        setHorizontalAlignment(CENTER);
        setVerticalAlignment(CENTER);
    }

    /*
     * This method finds the image and text corresponding
     * to the selected value and returns the label, set up
     * to display the text and image.
     */
    public Component getListCellRendererComponent(
                                       JList list,
                                       Object value,
                                       int index,
                                       boolean isSelected,
                                       boolean cellHasFocus) {

    	this.setText(((JLabel)value).getText());
    	this.setBackground(((JLabel)value).getBackground());
    	
    	if (isSelected && cellHasFocus){
    		this.setBackground(this.getBackground().darker());
    		this.setBorder(BorderFactory.createLineBorder(this.getBackground().darker(), 3));
    	}
    	else
    		this.setBorder(null);

        return this;
    }
}
